package api

import (
	"food-mgr/api-getaway/config"
	"food-mgr/api-getaway/handler/request"
	"food-mgr/api-getaway/response"
	__ "food-mgr/food-service/proto"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
	"strconv"
)

func ListOrder(c *gin.Context) {

	var order request.Order
	err := c.ShouldBind(&order)
	if err != nil {
		response.Error(c, "转化失败")
		return
	}
	page := c.Query("page")
	Pages, err := strconv.Atoi(page)
	if err != nil {
		return
	}
	size := c.Query("size")
	Sizes, err := strconv.Atoi(size)
	if err != nil {
		return
	}
	r, err := config.FoodClient.ListOrder(c, &__.ListOrderReq{
		Page:   int64(Pages),
		Size:   int64(Sizes),
		BizId:  int64(order.BizId),
		UserId: int64(order.UserId),
		Status: order.Status,
	})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}
	c.JSON(http.StatusOK, gin.H{
		"code": r.Code,
		"msg":  r.Msg,
		"data": r.List,
	})
}
